package pl.edu.agh.hypergraph;

import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
import pl.edu.agh.solid.Solid;
import pl.edu.agh.solid.SolidEdge;
import pl.edu.agh.solid.SolidVertex;
import edu.uci.ics.jung.graph.UndirectedSparseMultigraph;

public class FAH extends UndirectedSparseMultigraph<HV, HE> {

	private static final long serialVersionUID = 2129853690037725345L;
	final UUID id;

	public UUID getId() {
		return id;
	}

	HashMap<Integer, HV> int2hv = new HashMap<>();

	public FAH(Solid S) {
		super();
		this.id = S.getId();

		// hypergraph vertices

		for (int i = 0; i < S.getFaces().length; i++) {
			HV hv = new HV(S, i);
			int2hv.put(i, hv);
			this.addVertex(hv);
		}

		// hypergraph edges

		for (SolidEdge se : S.getEdges()) {

			HESimpleEdge e = new HESimpleEdge(S, se);

			HashSet<HV> vrtcs = new HashSet<>();

			vrtcs.add(int2hv.get(se.getFace1()));
			vrtcs.add(int2hv.get(se.getFace2()));

			this.addEdge(e, vrtcs);

		}

		// hypergraph hyperedges

		for (SolidVertex sv : S.getVertices()) {

			HEHyperEdge e = new HEHyperEdge(S, sv);
			HashSet<HV> vrtcs = new HashSet<>();

			for (int F : sv.getFaces())
				vrtcs.add(int2hv.get(F));

			this.addEdge(e, vrtcs);

		}

	}

}
